package com.bc.bcapi.service;

import com.bc.bccore.common.LoginHelper;
import com.bc.commoncore.security.AES;
import com.bc.commoncore.util.CookieUtils;
import com.bc.commoncore.util.StringUtils;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import org.springframework.stereotype.Service;
import org.web3j.abi.datatypes.Bool;

import javax.servlet.http.HttpServletRequest;

/**
 * @Name CommonImgCodeService
 * @Description TODO
 * @Author douhaichao
 * @Date 2018/9/18 13:44
 * @Version 1.0
 **/
@Service
public class CommonImgCodeService {

    /**
     * 判断验证码
     */
    public Boolean checkCode(HttpServletRequest request, String img_code, String cookie_name) {
        JsonResult js = new JsonResult();
        if (StringUtils.isEmpty(img_code)) {
            return false;
        }
        String value = CookieUtils.getCookie(request, cookie_name);
        String sessionCode = AES.aesDecrypt(value);
//        String sessionCode = LoginHelper.getAuthCode(request, cookie_name);
        if (sessionCode == null
                || !sessionCode.toString().toLowerCase()
                .equals(img_code.toLowerCase())) {
            return false;
        }
        return true;
    }
}
